package com.gjt.InternetAddress.thread;

import java.io.IOException;
import java.net.InetAddress;
import java.util.concurrent.Callable;

/**
 * Created with Intel IDEA.
 * 线程：功能就是解析日志文件，查找IP ,把ip 替换成相应的主机名，并返回
 *
 * @Auther: gjt
 * @Date: 2024/3/21 21:03
 */
public class LookupTask implements Callable<String> {

    private String line;

    public LookupTask(String line) {
        this.line = line;
    }

    @Override
    public String call() throws Exception {
        try{
            int index = line.indexOf(" ");
            String ip = line.substring(0,index);
            String reset = line.substring(index);
            String hostName = InetAddress.getByName(ip).getHostName();
            return  "主机名：" + hostName ;
        }catch (IOException e){
          return line;
        }
    }
}
